package GameStates;

import GameStates.StateManager.States;

import com.badlogic.gdx.Application.ApplicationType;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.GL10;
import com.badlogic.gdx.graphics.g2d.BitmapFont;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.math.Matrix4;
import com.me.mygdxgame.renderer.AssetsManager;
import com.me.mygdxgame.renderer.FontManager;
import com.me.mygdxgame.renderer.TextureManager;

public class MainMenu extends BaseState
{
	private final SpriteBatch spriteBatch;
	private boolean isDone = false;
	private final String fontFile = "data/default_font.fnt";
	private final String imgFile = "data/default_font.png";

	private Matrix4 viewMat = new Matrix4();
	private Matrix4 transMat = new Matrix4();

	public MainMenu()
	{
		ID = States.MAIN_MENU;

		spriteBatch = new SpriteBatch();

		TextureManager.getInstance().addTexture("main_menu","data/mario.jpg");
		FontManager.getInstance().addFont(fontFile, imgFile);

	}

	@Override
	public void pause()
	{

	}

	@Override
	public void update(float dt)
	{
		if (Gdx.input.justTouched())
		{
			isDone = true;
		}
	}

	@Override
	public void dispose()
	{
		spriteBatch.dispose();
		FontManager.getInstance().removeFont(fontFile, imgFile);

	}

	@Override
	public void draw(float dt)
	{
		Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT);

		viewMat.setToOrtho2D(0, 0, 480, 320);
		spriteBatch.setProjectionMatrix(viewMat);
		spriteBatch.setTransformMatrix(transMat);
		spriteBatch.begin();
		spriteBatch.disableBlending();
		spriteBatch.setColor(Color.WHITE);
		spriteBatch.draw(TextureManager.getInstance().getTexture("main_menu"), 0, 0, 480, 320,
				0, 0, 512, 512, false, false);
		spriteBatch.enableBlending();
		// spriteBatch.draw(logo, 0, 320 - 128, 480, 128, 0, 0, 512, 256, false,
		// false);
		spriteBatch.setBlendFunction(GL10.GL_ONE, GL10.GL_ONE_MINUS_SRC_ALPHA);
		String text = "Touch screen to start!";

		BitmapFont temp = AssetsManager.getInstance().get(fontFile,
				BitmapFont.class);

		float width = temp.getBounds(text).width;
		temp.draw(spriteBatch, text, 240 - width / 2, 128);
		if (Gdx.app.getType() == ApplicationType.WebGL)
		{
			text = "Press Enter for Fullscreen Mode";
			width = temp.getBounds(text).width;
			temp.draw(spriteBatch, "Press Enter for Fullscreen Mode",
					240 - width / 2, 128 - temp.getLineHeight());
		}
		spriteBatch.end();

	}

	@Override
	public boolean isDone()
	{
		return isDone;
	}

	@Override
	public void input(float dt)
	{

	}

}
